package weeek3.experience;

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Arraymethod {
    static int nDuanZhixuan=0;
    public static void main(String[] args) throws IOException {
        int[] b = new int[11];
        int c = 0;
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入数据");
        String a = scan.nextLine();
        StringTokenizer Tokennizer = new StringTokenizer(a);
        while (Tokennizer.hasMoreTokens()) {
            b[c] = Integer.parseInt(Tokennizer.nextToken());
            c++;
            nDuanZhixuan = c; }
        PrintArray(b);
        System.out.println("元素总数为" + nDuanZhixuan);
        File file = new File("C:\\Users\\24098\\duan_zhixuan_20172304java\\untitled\\src\\weeek3\\experience\\sort.txt");
        Reader reader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(reader);
        StringTokenizer Tokenizer = new StringTokenizer(bufferedReader.readLine());
        int ab[]=new int [2];
        int m=0;
        while(Tokenizer.hasMoreTokens())
        {
            ab[m]=Integer.parseInt(Tokenizer.nextToken());
            m++; }
        b=insertNode(5,b,ab[0]);PrintArray(b);
        System.out.println("元素总数为"+nDuanZhixuan);
        b=insertNode(0,b,ab[1]);PrintArray(b);
        System.out.println("元素总数为"+nDuanZhixuan);deletenode(ab[0],b);
        PrintArray(b);
        System.out.println("元素总数为"+nDuanZhixuan);
        b=selectsort(b);

    }

    public static int[] selectsort(int[] a) {
        for(int b=0;b<nDuanZhixuan;b++)
        {
            int num=0;
            for(int c=b;c<nDuanZhixuan;c++)
            {
                if(a[b]>a[c])
                {
                    int tem=a[b];
                    a[b]=a[c];
                    a[c]=tem;
                }

            }
        PrintArray(a);
            System.out.println("元素总数为"+nDuanZhixuan);
        }
    return a;
    }
    public static int[] insertNode(int index, int[]a, int data){
        if(nDuanZhixuan==a.length)
            a=expend(a);

        int []c=new int[a.length];
        int d=0;
        int f=0;
        for(int b=index;b<nDuanZhixuan;b++)
        {
            c[d]=a[b];
            d++;
        }
        a[index]=data;
        for(int b=index+1;b<nDuanZhixuan+1;b++)
        {
            a[b]=c[f];
            f++;
        }
        nDuanZhixuan++;
        return a;

    }//这是数组的插入方法
    public  static int[] expend(int[]a){
        int[]b=new int[a.length*2];
        int c=0;
        for(int d=0;d<nDuanZhixuan;d++)
        {
            b[c]=a[c];
            c++;
        }
        return b;
    }//这是数组的扩展方法
    public static int[] deledtenode(int[]a,int index){
        int b[]=new int [a.length];

        for(int c=index+1;c<nDuanZhixuan;c++)
        {
            b[c]=a[c];
        }
        for(int c=index;c<nDuanZhixuan-1;c++)
        {
            a[c]=b[c+1];
        }
        nDuanZhixuan--;
        return a;
    }//这是按照索引进行删除的方法；
    public static int[] deletenode(int data,int[]a)
    {
        int b=0;
        while(a[b]!=data){
            b++;
        }
        a=deledtenode(a,b);
    return a;
    }//实现搜索元素删除
        public static void  PrintArray(int[] b){
         for(int a=0;a<nDuanZhixuan;a++)
             System.out.print("元素"+b[a]+ " ");

        }
}
